package cn.tedu.rms.dish.service.impl;

import cn.tedu.rms.dish.mapper.DishMapper;
import cn.tedu.rms.dish.pojo.dto.DishQuery;
import cn.tedu.rms.dish.pojo.dto.DishSaveParam;
import cn.tedu.rms.dish.pojo.entity.Dish;
import cn.tedu.rms.dish.pojo.vo.DishVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class DishServiceImpl implements DishService{

    @Autowired
    private DishMapper dishMapper;
    @Override
    public List<DishVo> selectDish(DishQuery dishQuery) {
        log.debug("查询菜品信息，参数：{}",dishQuery);
        return dishMapper.selectDish(dishQuery);

    }

    @Override
    public void save(DishSaveParam dishSaveParam) {
        log.debug("保存菜品业务，参数：{}",dishSaveParam);
        Dish dish = new Dish();
        BeanUtils.copyProperties(dishSaveParam,dish);
        if (dish.getId()==null){
            log.debug("新增菜品业务");
            dish.setCreateTime(new Date());
            dishMapper.insert(dish);
        }else {
            log.debug("修改菜品业务");
            dish.setUpdateTime(new Date());
            dishMapper.update(dish);
        }
    }

    @Override
    public void deleteById(Long id) {
        log.debug("删除菜品业务，参数：{}",id);
        dishMapper.deleteById(id);
    }

    @Override
    public void updateStatus(Long id, String status) {
        log.debug("修改菜品状态业务，参数：{},{}",id,status);
        Dish dish = new Dish();
        dish.setId(id);
        dish.setStatus(status);
        dish.setUpdateTime(new Date());
        dishMapper.update(dish);
    }
}
